﻿using System;
using System.Diagnostics;
using System.Linq;
using Xunit;

namespace MyDemo
{
    /// <summary>
    /// Logging with Debug And Trace (一)
    /// http://www.cnblogs.com/LoveJenny/p/LoggingWithDebugAndTrace.html
    /// 如果要在release 模式下也记录日志的话，那么可以使用Trac
    /// </summary>
    public class TraceLog
    {
        [Fact]
        public void Test()
        {
            One();
            Two();
            RecursiveTest(0, 5);
        }

        private void One()
        {
            Trace.WriteLine("One");
        }

        private int Two()
        {
            Trace.WriteLine("Return 2");
            return 2;
        }

        private void RecursiveTest(int from, int to)
        {
            if (from < to)
            {
                var str = string.Join("", Enumerable.Repeat(" ", from)); // 显示空白字符串
                Trace.WriteLine($"{str} Enter Recursive Test:{from}");
                RecursiveTest(from + 1, to);
                Trace.WriteLine($"{str} Exit  Recursive Test:{from}");
            }
        }
    }
}